# -*- coding: utf-8 -*-
"""
author:码同学 极光
date:2025/3/8
desc: 
sample: 
"""
import json

import jsonpath

with open(file="test.json", encoding="utf-8") as f:
    json_str = f.read()

print(json_str)
json_dic=json.loads(json_str)
#$..price
#绝对路径 jsonpath   xpath /root/book[*]/title   //title
jsonpath_str=jsonpath.jsonpath(json_dic,"$.store.book[*].title")
print(jsonpath_str)

jsonpath_price=jsonpath.jsonpath(json_dic,"$..price")
print(jsonpath_price)

#相对路径..
jsonpath_str=jsonpath.jsonpath(json_dic,"$..title")
print(jsonpath_str)

checkurl = "$..book[0]"
jsonpath_str=jsonpath.jsonpath(json_dic,checkurl)
print(jsonpath_str[0].get("price"))